package com.dhcc.cdc.busi.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.dao.CdcUserMapper;
import com.dhcc.cdc.busi.entity.CdcDictionaryEntity;
import com.dhcc.cdc.busi.entity.CdcUserEntity;
import com.dhcc.cdc.busi.service.ICdcDictionaryService;
import com.dhcc.cdc.busi.service.ICdcUserService;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 业务用户表数据服务层接口
 * 
 * @ClassName: CdcUserServiceImpl
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:06
 */
@Service("cdcUserService")
public class CdcUserServiceImpl extends BaseServiceImpl<CdcUserMapper, CdcUserEntity> implements ICdcUserService {

	@Autowired
	private ICdcDictionaryService cdcDictionaryService;

	@Override
	public List<CdcUserEntity> page(Page<CdcUserEntity> page, Map<String, Object> map) {
		return this.baseMapper.page(page, map);
	}
	@Override
	public List<CdcUserEntity> list(Map<String, Object> map) {
		return this.baseMapper.list(map);
	}

	@Override
	public JSONArray getUserMap(String code) {
		JSONArray userArry = new JSONArray();
		CdcDictionaryEntity cdcDictionaryEntity = cdcDictionaryService.queryByTypeCodeAndCode("HisBase", "bus_user_type", code);
		JSONObject obj = new JSONObject();
		obj.put("value", "");
		obj.put("text","全部");
		userArry.add(obj);
		if (CommonUtil.isNotEmpty(cdcDictionaryEntity)){
			List<CdcUserEntity> cdcUserEntities = this.baseMapper.selectList(new EntityWrapper<CdcUserEntity>()
					.eq("bus_user_type_id", cdcDictionaryEntity.getId()));
			for(CdcUserEntity cdcUserEntity : cdcUserEntities){
				JSONObject userObj = new JSONObject();
				userObj.put("value", cdcUserEntity.getId() + "");
				userObj.put("text", cdcUserEntity.getName());
				userArry.add(userObj);
			}
		}
		return userArry;
	}

}